﻿Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports NUnit.Framework

Namespace Axial.Tests
    <TestFixture()> _
    Public Class IfTests
        Inherits TestBase
        <Test()> _
        Public Sub SimpleTest()
            Dim check As String = "if (a > b)" & vbNewLine & vbTab & "a = 3;"
            VerifyMethodOutput("Simple", check)
        End Sub
        Public Sub Simple()
            Dim a As Integer = 2, b As Integer = 1
            If a > b Then
                a = 3
            End If
        End Sub

        <Test()> _
        Public Sub ElseTest()
            Dim check As String = "if (a > b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "else" & vbNewLine & vbTab & "a = 4;"
            VerifyMethodOutput("Else", check)
        End Sub
        Public Sub [Else]()
            Dim a As Integer = 2, b As Integer = 1
            If a > b Then
                a = 3
            Else
                a = 4
            End If
        End Sub

        <Test()> _
        Public Sub ConditionsTest()
            Dim check As String = "if (a == b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (a != b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (a > b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (a >= b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (a <= b)" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (a < b)" & vbNewLine & vbTab & "a = 3;"
            VerifyMethodOutput("Conditions", check)
        End Sub
        Public Sub Conditions()
            Dim a As Integer = 2, b As Integer = 1
            If a = b Then
                a = 3
            End If
            If a <> b Then
                a = 3
            End If
            If a > b Then
                a = 3
            End If
            If a >= b Then
                a = 3
            End If
            If a <= b Then
                a = 3
            End If
            If a < b Then
                a = 3
            End If
        End Sub

        <Test()> _
        Public Sub OrTest()
            Dim check As String = "if (a == b || c == 4)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("Or", check)
        End Sub
        Public Sub [Or]()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c = 4 Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub OrAndTest()
            Dim check As String = "if (a == b || c == 4 && a == c)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("OrAnd", check)
        End Sub
        Public Sub OrAnd()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c = 4 AndAlso a = c Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub AndTest()
            Dim check As String = "if (a == b && c == 4)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("And", check)
        End Sub
        Public Sub [And]()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub AndOrTest()
            Dim check As String = "if (a == b && c == 4 || a == c)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("AndOr", check)
        End Sub
        Public Sub AndOr()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 OrElse a = c Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub AndOrIfTest()
            Dim check As String = _
"if (a == b && c == 4 || a == c)" & vbNewLine & _
vbTab & "if (b == 2)" & vbNewLine & _
vbTab & vbTab & "a = 15;"
            VerifyMethodOutput("AndOrIf", check)
        End Sub
        Public Sub AndOrIf()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 OrElse a = c Then
                If b = 2 Then
                    a = 15
                End If
            End If
        End Sub

        <Test()> _
        Public Sub AndOrIfStatementTest()
            Dim check As String = _
"if (a == b && c == 4 || a == c)" & vbNewLine & _
vbTab & "if (b == 2)" & vbNewLine & _
vbTab & vbTab & "a = 15;" & vbNewLine & _
"d = -1;"
            VerifyMethodOutput("AndOrIfStatement", check)
        End Sub
        Public Sub AndOrIfStatement()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            Dim d As Integer
            If a = b AndAlso c = 4 OrElse a = c Then
                If b = 2 Then
                    a = 15
                End If
            End If
            d = -1
        End Sub

        <Test()> _
        Public Sub AndOrAndTest()
            Dim check As String = "if (a == b && c == 4 || a == c && b == 2)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("AndOrAnd", check)
        End Sub
        Public Sub AndOrAnd()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 OrElse a = c AndAlso b = 2 Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub AndAndIfTest()
            Dim check As String = "if (a == b && c == 4 && a == c && b == 2)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("AndAndIf", check)
        End Sub
        Public Sub AndAndIf()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 AndAlso a = c Then
                If b = 2 Then
                    a = 15
                End If
            End If
        End Sub

        <Test()> _
        Public Sub AndIfAndTest()
            Dim check As String = "if (a == b && c == 4 && b == 2 && a == c)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("AndIfAnd", check)
        End Sub
        Public Sub AndIfAnd()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 Then
                If b = 2 AndAlso a = c Then
                    a = 15
                End If
            End If
        End Sub

        <Test()> _
        Public Sub OrAndIfTest()
            Dim check As String = "if (a == b || c == 4 && a == c)" & vbNewLine & vbTab & "if (b == 2)" & vbNewLine & vbTab & vbTab & "a = 15;"
            VerifyMethodOutput("OrAndIf", check)
        End Sub
        Public Sub OrAndIf()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c = 4 AndAlso a = c Then
                If b = 2 Then
                    a = 15
                End If
            End If
        End Sub

        <Test()> _
        Public Sub And3Test()
            Dim check As String = "if (a == b && c == 4 && a == 2)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("And3", check)
        End Sub
        Public Sub And3()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c = 4 AndAlso a = 2 Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub Or3Test()
            Dim check As String = "if (a == b || c == 4 || a == 2)" & vbNewLine & vbTab & "a = 15;"
            VerifyMethodOutput("Or3", check)
        End Sub
        Public Sub Or3()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c = 4 OrElse a = 2 Then
                a = 15
            End If
        End Sub

        <Test()> _
        Public Sub VeryLongTest()
            Dim check As String = "if (a == b && c != 4 && a > 2 && b < 3 && a >= c && c <= b && a == 3)" & vbNewLine & vbTab & "a = 10;"
            VerifyMethodOutput("VeryLong", check)
        End Sub
        Public Sub VeryLong()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c <> 4 AndAlso a > 2 AndAlso b < 3 AndAlso a >= c AndAlso c <= b AndAlso a = 3 Then
                a = 10
            End If
        End Sub

        <Test()> _
        Public Sub VeryLongMixedTest()
            Dim check As String = "if (a == b || c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)" & vbNewLine & vbTab & "a = 10;"
            VerifyMethodOutput("VeryLongMixed", check)
        End Sub
        Public Sub VeryLongMixed()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c <> 4 OrElse a > 2 AndAlso b < 3 OrElse a >= c AndAlso c <= b OrElse a = 3 Then
                a = 10
            End If
        End Sub

        <Test()> _
        Public Sub VeryLongMixedTest2()
            Dim check As String = "if (a == b && c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)" & vbNewLine & vbTab & "a = 10;"
            VerifyMethodOutput("VeryLongMixed2", check)
        End Sub
        Public Sub VeryLongMixed2()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b AndAlso c <> 4 OrElse a > 2 AndAlso b < 3 OrElse a >= c AndAlso c <= b OrElse a = 3 Then
                a = 10
            End If
        End Sub

        <Test()> _
        Public Sub VeryLongMixedTest3()
            Dim check As String = "if (a == b || c != 4 && a > 2 && b < 3 || a >= c && c <= b || a == 3)" & vbNewLine & vbTab & "a = 10;"
            VerifyMethodOutput("VeryLongMixed3", check)
        End Sub
        Public Sub VeryLongMixed3()
            Dim a As Integer = 2, b As Integer = 1, c As Integer = 3
            If a = b OrElse c <> 4 AndAlso a > 2 AndAlso b < 3 OrElse a >= c AndAlso c <= b OrElse a = 3 Then
                a = 10
            End If
        End Sub

        <Test()> _
        Public Sub IfIfTest()
            VerifyMethodOutput("IfIf", "if (a == 1)" & vbNewLine & vbTab & "a = 2;" & vbNewLine & "if (b == 2)" & vbNewLine & vbTab & "b = 1;")
        End Sub
        Public Sub IfIf()
            Dim a As Integer = 0
            Dim b As Integer = 1
            If a = 1 Then
                a = 2
            End If
            If b = 2 Then
                b = 1
            End If
        End Sub

        <Test()> _
        Public Sub ElseIfTest()
            VerifyMethodOutput("ElseIf", "if (a == 1)" & vbNewLine & vbTab & "a = 2;" & vbNewLine & "else" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (b == 2)" & vbNewLine & vbTab & "b = 1;")
        End Sub
        Public Sub [ElseIf]()
            Dim a As Integer = 0
            Dim b As Integer = 1
            If a = 1 Then
                a = 2
            Else
                a = 3
            End If
            If b = 2 Then
                b = 1
            End If
        End Sub

        <Test()> _
        Public Sub OrElseIfTest()
            VerifyMethodOutput("OrElseIf", vbNewLine & "if (a == 1 || b == 2)" & vbNewLine & vbTab & "a = 2;" & vbNewLine & "else" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (b == 3)" & vbNewLine & vbTab & "b = 1;")
        End Sub
        Public Sub OrElseIf()
            Dim a As Integer = 0
            Dim b As Integer = 1
            If a = 1 OrElse b = 2 Then
                a = 2
            Else
                a = 3
            End If
            If b = 3 Then
                b = 1
            End If
        End Sub

        <Test()> _
        Public Sub AndElseIfTest()
            VerifyMethodOutput("AndElseIf", vbNewLine & "if (a == 1 && b == 2)" & vbNewLine & vbTab & "a = 2;" & vbNewLine & "else" & vbNewLine & vbTab & "a = 3;" & vbNewLine & "if (b == 3)" & vbNewLine & vbTab & "b = 1;")
        End Sub
        Public Sub AndElseIf()
            Dim a As Integer = 0
            Dim b As Integer = 1
            If a = 1 AndAlso b = 2 Then
                a = 2
            Else
                a = 3
            End If
            If b = 3 Then
                b = 1
            End If
        End Sub

        <Test()> _
        Public Sub ElseNestedIfElseTest()
            VerifyMethodOutput("ElseNestedIfElse", _
"if (a == 1)" & vbNewLine & _
"{" & vbNewLine & _
"	if (b == 2)" & vbNewLine & _
"		b = 3;" & vbNewLine & _
"	else" & vbNewLine & _
"		a = 3;" & vbNewLine & _
"}" & vbNewLine & _
"else" & vbNewLine & _
"	a = 2;")
        End Sub
        Public Sub ElseNestedIfElse()
            Dim a As Integer = 0
            Dim b As Integer = 1
            If a = 1 Then
                If b = 2 Then
                    b = 3
                Else
                    a = 3
                End If
            Else
                a = 2
            End If
        End Sub
    End Class
End Namespace